Repository navigation
test(quota): carry prepared lease into native recovery writeback - #9131
Conversation
Signed-off-by: lusendong.6789 <[email protected]> Co-authored-by: TRAE CLI <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google DeepMind · self_reported
动机 / Motivation
在主干维护控制面测试套件的开发者与自动化回归门禁会在执行原生恢复回归用例时触发该前置失败。修复前:手动 refresh-state 缺少 lease_proof 参数而在护栏处直接报错中断;修复后:从 ready 响应提取 execution_preparation.lease_proof 并传入 --task-lease-idempotency-key 与 --task-lease-expected-version,使测试顺利穿透首轮写回护栏并完整校验后续释放租约、PostToolUse 拒绝重入、文件/事件不可变及单次配额扣减断言。tests/control_plane/test_quota_execution_preparation.py::test_restored_native_capture_does_not_claim_after_manual_writeback 的全部 4 组参数化组合(file/sqlite × spend_committed False/True)均从失败恢复为 PASS,且未弱化任何原有断言。本 PR 不修改任何生产控制面逻辑、TypeScript 决策拥有者、CLI 参数解析或原生 Hook 隔离策略,也不替代仍在进行中的 C1 端到端宿主验收。
背景原因在于主干 PR #9111(commit d1f72b3350 / 2f4c4e92c3)引入 guard_first_writeback_execution 后,当 Todo 仍处于 open 状态且 should-run 已记录 prepared_lease 时,首轮 refresh-state 写回必须携带匹配的 --task-lease-idempotency-key 与 --task-lease-expected-version。既有测试在手工构造 refresh-state 命令时遗漏了这两项参数,导致测试在进入真正的原生捕获恢复断言之前就被护栏拦截失败。
改动思路 / Approach
本次审查对比了不做修改、放宽护栏与修复测试调用三种选择:显然主干生产护栏(loopx/control_plane/quota/execution_preparation.py#L206-L241)在 Todo 仍为 open 时要求显式携带原始租约证明是正确且必要的安全约束,而真实生产路径(loopx/control_plane/quota/settlement_plan.ts#L43-L50 与 loopx/cli_commands/turn_run_once.py#L389-L390)也确实从 execution_preparation.lease_proof 中透传该证明。因此最小且唯一正确的修法就是让测试夹具消费同一个 ready["execution_preparation"]["lease_proof"] 字段,不新增任何生产分支、helper 或兼容兜底。
具体改动 / Changes
本次改动(head 1e4801f2a7991305fc07f8c025c74f3350cc4ff8)仅涉及单个测试文件 tests/control_plane/test_quota_execution_preparation.py(+3/-0 行),无独立 RFC 或协议规格变更:
- 在
test_restored_native_capture_does_not_claim_after_manual_writeback第 579 行提取proof = ready["execution_preparation"]["lease_proof"]。 - 在第 586-587 行为手动
refresh-state调用追加--task-lease-idempotency-key与--task-lease-expected-version。 - 逐行核对第 591-612 行的全部后置断言,确认释放租约、重放旧捕获触发
already settling or settled、禁止重新 claim、原捕获字节与rollout-event-log.jsonl保持不变,以及quota spend-slot幂等重放与最终仅扣减 1 次配额的断言均原样保留、未做任何削弱。此外排查仓库中其他should-run与手动refresh-state组合用例,未发现同类遗漏。
对主干的风险 / Risks
未发现阻塞性缺陷(No blocking findings)。变更完全局限在单个测试夹具的 3 行参数补齐,不改变任何生产运行路径、持久化格式或默认行为;回滚仅需撤回该 3 行改动。
独立验证结果(全部在隔离 worktree 与真实 file/sqlite 后端下执行):
- 精确修复的 4 组恢复用例(
test_restored_native_capture_does_not_claim_after_manual_writeback):PASS(4 passed, 83 deselected in 17.77s)。 - 同文件完整套件(
tests/control_plane/test_quota_execution_preparation.py):PASS(87 passed in 33.32s)。 - 关联租约与原生恢复套件(7 个文件,含
test_codex_execution_preparation.py、test_codex_context_resume.py、test_split_root_todo_writeback_fence.py、test_task_lease_cli.py、test_turn_run_once_claim_preparation.py、test_codex_context_lifecycle.py与test_turn_recovery_state_machine.py):PASS(195 passed in 23.55s+172 passed in 76.25s)。 ruff check、双语 RFC 门禁、loopx check --scan-path与loopx canary premerge --tier quick(3/3 catalog canaries):PASS。
残余风险与验证边界:该测试使用本地 git worktree 与环境变量 CODEX_THREAD_ID 模拟宿主会话投递,未覆盖外部真实 Codex App 进程端到端拉起;另隔离 worktree 未安装 node_modules 中的 typescript 开发依赖,但本 PR 未改动任何 TypeScript 文件。
我的整体评价 / Verdict
本 PR 是一次精准、克制且对主干测试健康有明确正向价值的修复(+3/-0 行),在不改动生产护栏的前提下,完整恢复了原生上下文捕获遭遇手动写回与租约释放后的核心防重入验证。长程稳定性保持不变(long_horizon: preserved),无交互与视觉界面影响(user_experience: not_applicable),无重复 smoke 或刷量问题,建议合入。
English verdict: APPROVE — exact head 1e4801f2a7991305fc07f8c025c74f3350cc4ff8 cleanly restores all 4 File/SQLite native recovery cases without weakening assertions (87 passed in test_quota_execution_preparation.py, 367 passed across 7 related lease/recovery suites, ruff/check/canary quick premerge all PASS; no blocking findings).
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
动机 / Motivation
维护原生会话恢复回归的开发者,原先在首轮写回被拒后,无法验证用户重开会话的恢复路径。 同一运行时代码下,基线夹具的四种组合都在首轮写回失败。新增三行传入原租约后,四种组合均通过并执行了尾部复验。 File 和 SQLite 各覆盖首轮只写回、首轮已扣额两个分支。恢复钩子保留原捕获字节、原认领回执和事件日志,释放的租约不再认领,重试后只扣一次。 改动只修正已有回归测试的调用。当前验收覆盖本地 CLI 与合成的宿主事件。 真实 Codex 界面恢复和部署采用属于后续宿主验收。
改动思路 / Approach
测试从当次准入返回的 ready receipt 取得租约 key 和版本,交给已有的 refresh-state 护栏。真实写回负责检验原 lease,测试只提供原本由客户端携带的证明。放宽护栏会失去过期与换租约的拒绝路径,另建回归也会重复这组已经存在的恢复断言。
具体改动 / Changes
基线 f80e6c4,审查提交 1e4801f。单个既有测试文件净增三行。新增变量来自同一 ready 结果,两项 CLI 参数沿用已注册的写回协议。测试改动
上下文恢复约定 对应三个验收点。首轮写回需要与原 Turn 关联的租约,丢失宿主观察后读取原始捕获,确认效果后恢复只读回旧凭据。测试还核对支出计数和两次 hook 调用的稳定结果。运行时文件、协议和值域没有改动。
对主干的风险 / Risks
基线四组在 refresh-state 中断。独立获取的原诊断为 refresh_task_lease_unavailable。精确提交走完 File 和 SQLite 的四组恢复分支,范围包括已扣额和未扣额。原断言仍验证释放后拒绝再认领、捕获及事件字节不变,最终配额记一次。两个本地测试文件共 158 项通过。Quick premerge 的 5 项直接检查和 3 项选定检查均通过。 首次测试命令引用了不存在的文件,改为实际执行准备与 authority settlement 测试后重跑。远端 CI 未查。
我的整体评价 / Verdict
批准。保留既有权威和自动恢复边界,让回归测试重新覆盖丢失的后半段。最小修复复用当前写回参数,生产入口和默认行为保持一致。改动在测试夹具,无渲染界面。需要另行验收的范围为部署采用、实际 Codex 宿主和模型效果。
English verdict: APPROVE at 1e4801f. The existing four recovery cases now reach their original lease, capture, and once-only debit assertions.
The native-recovery fixture fails at its first manual
refresh-statecall because the prepared-Turn fence now requires the original lease proof. Carry the proof from the ready guard into that writeback so the test reaches its intended recovery checks: no new claim after release, unchanged original capture and receipts, and one quota debit across retries.原生恢复测试的手写写回调用遗漏了当前 fence 要求的 lease proof,导致测试在进入恢复分支前失败。本变更使用原 ready guard 提供的 proof;保留释放后不重认领、原捕获与回执不改写、重试只扣一次配额的全部断言。只修复现有测试调用,无运行时或默认行为变更。
Validation at
1e4801f2a7991305fc07f8c025c74f3350cc4ff8, based onmain@f80e6c4412783a9d5c157e0769cebc872eef5bf7:dca761a9e5e022d847ff910823d4639382fa0b79.An optional native Code Mode isolation probe remains unqualified: the older CLI fails the expected hook inventory, while current and pinned CLIs expose additional managed hooks, so the isolated fixture refuses them before dispatch. No hook trust was broadened. This test repair enables the existing C1 migration qualification; it does not establish installed adoption, model feedback benefit or complete C1 cutover. The existing migration and acceptance work remains open.
UI impact: none. Bounded refactoring: unnecessary; the existing test consumes the existing typed proof without adding a helper or owner. All commits carry DCO sign-off.